﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Configuration;

namespace AutoSendMail
{
    public partial class MailConfig : Form
    {
        public MailConfig()
        {
            InitializeComponent();
            string user = ConfigurationManager.AppSettings["user"];
            string password = ConfigurationManager.AppSettings["password"];
            string mail = ConfigurationManager.AppSettings["mail"];
            string smtpserver = ConfigurationManager.AppSettings["smtpserver"];
            textBox1.Text = user;
            textBox2.Text = password;
            textBox3.Text = mail;
            textBox4.Text = smtpserver;
        }

        private void Button1_Click(object sender, EventArgs e)
        {
            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            config.AppSettings.Settings["user"].Value = textBox1.Text;
            config.AppSettings.Settings["password"].Value = textBox2.Text;
            config.AppSettings.Settings["mail"].Value = textBox3.Text;
            config.AppSettings.Settings["smtpserver"].Value = textBox4.Text;
            config.Save(ConfigurationSaveMode.Full);
            ConfigurationManager.RefreshSection("appSettings");
        }
        private void Button2_Click(object sender, EventArgs e)
        {
            foreach (var item in Controls)
            {
                if (item is TextBox)
                {
                    ((TextBox)item).Text = "";
                }
            }
        }
    }
}
